package testes;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import criptografia.Encriptador;

public class TestaEncriptador {
	
	private Encriptador encriptador;
	private byte[] teste;
	@Before public void antesDosTestes() throws Exception{
		encriptador = new Encriptador();
		teste = encriptador.encriptar("teste");
	}
	
	@Test public void testaEncriptar(){
		try{
			Assert.assertEquals("teste", encriptador.decriptar(teste));
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
	}
	
	@Test  public void testaEncriptar1(){
		try{
			encriptador.encriptar(null);
			Assert.fail();
				
		}catch(Exception e){
			Assert.assertEquals("A string nao pode ser nula", e.getMessage());
		}
	}
	
	@Test public void testaEncriptar2(){
		try{
			byte[] dado = encriptador.encriptar(10);
			Assert.assertEquals("10", encriptador.decriptar(dado));
		}catch(Exception e){
			
		}
	}
	
	@Test public void testaHash(){
		try{
			Assert.assertEquals(encriptador.geraHashParaSenha("s3nh4"), encriptador.geraHashParaSenha("s3nh4"));
			Assert.assertFalse(encriptador.geraHashParaSenha("s3nh4").equals(encriptador.geraHashParaSenha("senha")));
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
	}
	
	@After
	public void fimDosTestes(){
		System.out.println("Fim do teste de Encriptador");
	}
}
